package com.chy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chy.common.R;
import com.chy.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping("/add")
    public R<String> addArticle(@RequestBody Map<String, Object> params) {
        return articleService.addArticle(params);
    }

    @PostMapping("/list")
    public R<Page> getArticleList(@RequestBody Map<String, Object> params) {
        Page pageInfo = articleService.selectByPage(params);
        return R.success(pageInfo);
    }

    @PostMapping("/manageList")
    public R<Page> getArticleManageList(@RequestBody Map<String, Object> params) {
        Page pageInfo = articleService.selectByPage(params);
        return R.success(pageInfo);
    }

    @PostMapping("/getArtById")
    public R<Object> getArtById(@RequestBody Map<String, Object> params) {
        return articleService.getArtById(params);
    }

    @PostMapping("/update")
    public R<String> updateArticle(@RequestBody Map<String, Object> params) {
        return articleService.updateArticle(params);
    }

    @PostMapping("/delete")
    public R<String> deleteArticle(@RequestBody List<Map<String, Object>> lists) {
        return articleService.deleteArticle(lists);
    }

}
